const koa = require('koa');
const app = new koa();
const path = require('path');
const error = require('koa-onerror');
const static = require('koa-static');
const favicon = require('koa-favicon');
const render = require('koa-art-template');
const bodyParser = require('koa-bodyparser')
const logger = require('koa-logger')
const json = require('koa-json')
const port = 7100;
const debug = console.log.bind(this);

const index = require('./routes/index');

error(app)

app.use(static(path.join(__dirname, 'public')))
app.use(favicon(__dirname + '/public/favicon.ico'))

app.use(bodyParser())
app.use(logger())
app.use(json())
// 配置模板引擎
render(app, {
  root: path.join(__dirname, 'views'), // 视图目录
  extname: '.html',
  debug: process.env.NODE_ENV !== 'production'
})

app.use(index.routes());

app.listen(port, () => {
  debug(`Success, Welcome to Koa\nPort:${port}`);
})